package com.etc.serviceimpl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.etc.dao.UserMapper;
import com.etc.entity.User;
import com.etc.service.UserService;
import com.etc.tools.MD5Util;
import com.etc.tools.PageData;

/**
 * wwb 4-27
 * 
 * @author Administrator
 *
 */
@Service(value = "userService")
public class UserServiceImpl implements UserService {
	@Resource
	private UserMapper um;

	/**
	 * 
	 */
	@Override
	public int deleteByPrimaryKey(Integer uid) {

		return um.deleteByPrimaryKey(uid);
	}

	@Override
	public int insert(User record) {
		record.setUpwd(MD5Util.getEncodeByMd5(record.getUpwd()));
		return um.insert(record);
	}

	@Override
	public int insertSelective(User record) {
		record.setUpwd(MD5Util.getEncodeByMd5(record.getUpwd()));
		return um.insertSelective(record);
	}

	@Override
	public User selectByPrimaryKey(Integer uid) {

		return um.selectByPrimaryKey(uid);
	}

	@Override
	public int updateByPrimaryKeySelective(User record) {

		return um.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(User record) {

		return um.updateByPrimaryKey(record);
	}
	// wwb 4.27 user 增删改查结束！

	// 分页
	@Override
	public PageData<User> getUsersBypage(int page, int pagesize, String content) {
		int start = (page - 1) * pagesize;
		List<User> data = um.selectUserBypage(start, pagesize, content);
		int count = um.selecCount(content);
		PageData<User> pd = new PageData<User>(data, count, pagesize, page);
		return pd;
	}

	// 状态修改
	@Override
	public boolean changeStatus(User record) {
		boolean flag = false;
		if (record.getUstatus() == 0) {
			record.setUstatus(1);
			flag = um.updateStatus(record);
		} else {
			record.setUstatus(0);
			flag = um.updateStatus(record);
		}
		return flag;
	}

	// 账户校验
	@Override
	public boolean nameCheck(String name) {
		boolean flag = false;
		if (name != null) {
			User user = um.selectUserByName(name);
			if (user != null) {
				flag = true;
			}
		}
		return flag;
	}

	// 登录校验
	@Override
	public User logining(String name) {
		User user = um.selectUserByName(name);
		return user;
	}
    //批量删除
	@Override
	public boolean deleteUsers(int[] arr) {
		// TODO Auto-generated method stub
		return um.deleteUsers(arr);
	}

}
